package com.zygh.lz.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zygh.lz.entity.Account;
import com.zygh.lz.entity.Staff;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface AccountMapper  extends BaseMapper<Account> {
    @Select(" <script> select a.*,sr.name as roleName,sc.section_name as sectionName from account a left join sys_role sr on  a.sys_role_id = sr.id" +
            " left join section sc on sc.sys_section_id =a.sys_section_id \n" +
            "<where> \n" +
            "<if test='unit != null '>and exists ( select 1 from section where  sys_section_id =a.sys_section_id  and section_name = #{unit} )</if>\n" +
            "<if test='staffSex != null'> and a.staff_sex = #{staffSex} </if>\n" +
            "<if test = 'staffNum != null'>and a.staff_num like  concat('%',#{staffNum},'%')</if>\n" +
            " <if test = 'staffTel != null'>and a.staff_tel like  concat('%',#{staffTel},'%')</if> " +
            " <if test = 'sysRoleId != null'>and a.sys_role_id = #{sysRoleId}</if> " +
            " <if test = 'sysSectionId != null'>and a.sys_section_id = #{sysSectionId}</if> " +
            "</where>  </script>")
    List<Map> select(Account account);
    @Select("       select * from account f,section c where f.staff_tel = #{user}" +
            "      and f.staff_password= #{password}\n" +
            "      AND f.sys_section_id=c.sys_section_id")
    Account selectByLogin(@Param("user") String user,@Param("password") String staff_password);
@Select("        SELECT\n" +
        "            DISTINCT rm.menu_id\n" +
        "        FROM\n" +
        "            sys_user_role ur\n" +
        "        LEFT JOIN sys_role_menu rm ON ur.role_id = rm.role_id LEFT JOIN sys_menu sm ON rm.menu_id = sm.id\n" +
        "        WHERE ur.user_id = #{userId} and sm.statu = 1")
    List<Long> getNavMenuIds(Long userId);
}
